package com.qys.livesMall.open.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.qys.livesMall.framework.utils.SecurityUtils;
import com.qys.livesMall.framework.view.BaseQuery;
import com.qys.livesMall.open.enums.PushMessageTypeEnum;
import com.qys.livesMall.open.modal.dto.app.OpenSysMessagePageDTO;
import com.qys.livesMall.open.modal.entity.H2OpenSysMessage;
import com.qys.livesMall.open.mapper.H2OpenSysMessageMapper;
import com.qys.livesMall.open.modal.vo.OpenSysMessageVo;
import com.qys.livesMall.open.service.H2OpenSysMessageService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import jakarta.annotation.Resource;
import jodd.util.StringUtil;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import java.time.ZoneOffset;
import java.util.List;

/**
 * <p>
 * 系统信息 服务实现类
 * </p>
 *
 * @author wzy
 * @since 2023-07-11
 */
@Service
public class H2OpenSysMessageServiceImpl extends ServiceImpl<H2OpenSysMessageMapper, H2OpenSysMessage> implements H2OpenSysMessageService {
    @Resource
    private H2OpenSysMessageMapper mapper;
    @Override
    public Page<OpenSysMessageVo> querpage(BaseQuery dto) {
        Page<OpenSysMessageVo> page = new Page<>(dto.getPageNum(), dto.getPageSize());
        if(SecurityUtils.getLoginUser()==null){
            return null;
        }
        List<OpenSysMessageVo> voList=mapper.list(page, SecurityUtils.getUserId());
        if (CollectionUtils.isNotEmpty(voList)){
            voList.forEach(a->{
                a.setCreatelongtime(a.getCreateTime().toInstant(ZoneOffset.ofHours(8)).toEpochMilli());
            });
        }
        page.setRecords(voList);
        return page;
    }

    @Override
    public OpenSysMessageVo getSysMessage(Long id) {
        return mapper.getSysMessage( SecurityUtils.getUserId(),id);
    }

    @Override
    public List<OpenSysMessageVo> messageBySys() {
        List<OpenSysMessageVo> voList=mapper.messageBySys();
        if (CollectionUtils.isNotEmpty(voList)){
            voList.forEach(a->{
                a.setCreatelongtime(a.getCreateTime().toInstant(ZoneOffset.ofHours(8)).toEpochMilli());
            });
        }
        return voList;
    }
}
